# Maintainer: Clayton Craft <clayton@craftyguy.net>
# Co-Maintainer: Caleb Connolly <caleb@postmarketos.org>
pkgname=linux-postmarketos-qcom-laptop
pkgver=6.12
pkgrel=1
# Commit from branch @ https://github.com/jhovold/linux/tree/wip/x1e80100-$pkgver
_commit="93bd777d19aa0e8b58dee1eb837a16acf56035b0"
pkgdesc="Generic kernel for Qualcomm laptops"
arch="aarch64"
_carch="arm64"
_flavor="postmarketos-qcom-laptop"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip
	!check
	!tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-containers
	pmb:kconfigcheck-uefi
"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	findutils
	flex
	git
	openssl-dev
	perl
	python3
	zstd
"
replaces="linux-lenovo-21bx"

# Source
_repository="linux"
source="
	$pkgname-$_commit.tar.gz::https://github.com/jhovold/$_repository/archive/$_commit.tar.gz
	misc.config
	pmos.config
"
builddir="$srcdir/linux-$_commit"
_outdir="out"
_defconfig="johan_defconfig"

prepare() {
	default_prepare
	cp "$srcdir/pmos.config" "$builddir"/arch/"$_carch"/configs/
	cp "$srcdir/misc.config" "$builddir"/arch/"$_carch"/configs/

	# Generate .config
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor" \
		"$_defconfig" pmos.config misc.config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	install -Dm644 "$builddir/arch/$_carch/boot/vmlinuz.efi" \
			"$pkgdir/boot/linux.efi"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs

	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
af20b0d7e46e31de152a01e6c811c691f3866add856d4b8cc3e665fde2f10d0fa4ccb401cf3583e4975c0ccb281369fc019825ad274c4edad49f0e8069c154fc  linux-postmarketos-qcom-laptop-93bd777d19aa0e8b58dee1eb837a16acf56035b0.tar.gz
c343baeb03f91a16994fd53e7cf1be0590be591c3a02e583d897f6b84ee9b33662cac513f84e1756fed58ab283c16471492bf227a1adb00f5bdd660ea4631ef1  misc.config
98c3d46a83f496ed3cdb0ae97f9a891ff2acb504205d91646bed23b2efc999d77f486ec905ceebdac08a9d25f51b82caec8857311434a4d9de214f064541df96  pmos.config
"
